package com.ruoyi.utils;

import java.util.Calendar;

import com.sudytech.ucp.serv.Address;
import com.sudytech.ucp.serv.Message;
import com.sudytech.ucp.serv.MessagePropertiesEntry;
import com.sudytech.ucp.serv.SendResult;
import com.sudytech.ucp.serv.UcpWebServProxy;

public class NyMessageSendUtil {
	static final String appId = "CN=shiyanshi.njupt.edu.cn,OU=njupt,O=njupt,L=NJ,ST=JS,C=CN";
	static final String privateKey = "d1a52cd7-90e0-41b4-9265-84d5a85b0c6f";
	static final String wsUrl = "http://ucp.njupt.edu.cn/UcpWebServ?wsdl";
	static int boxId = 3400;
	static Integer[] channels = { 1 };
	
	public static String MsgType_UC_UX =  "uc_ux";

	public static SendResult sendMsg(String subject, String content, String type, String address) {
		Address[] addressList = new Address[] { new Address(address, type) };
		Message message = new Message();
		message.setTo(addressList);
		message.setSubject(subject);
		message.setContent(content);
		message.setMsgType(0);
		MessagePropertiesEntry signature = new MessagePropertiesEntry("smsSignature", null);
		message.setProperties(new MessagePropertiesEntry[] { signature });
		Calendar planTime = Calendar.getInstance();
		planTime.add(Calendar.MINUTE, 1);
		try {
			String serviceToken = new TokenBuilder(appId, privateKey).buildToken();
			SendResult sendResult = new UcpWebServProxy(wsUrl).getUcpWebServ_PortType().sendMessage(boxId, message,
					channels, true, null, serviceToken);
			return sendResult;
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}

}
